<template>
  <view class="distribution" @click="$emit('toAddress')">
    <template v-if="address && address.id && csa != 1">
      <view class="distribution-top">
        <template v-if="!isShop || true">
          <view class="distribution-address"
            >{{ address.province }}{{ address.city }}{{ address.district }}
          </view>
          <view class="distribution-addressdetails">
            <view class="addressdetails">{{ address.detail }}</view>

            <i
              class="iconfont icon-arrow-right"
              style="font-size: 22rpx; color: #cdcdcd"
            ></i>
          </view>
          <view class="distribution-name">
            <view>{{ address.name }}</view>
            <view>{{ address.mobile | noPassByMobile }}</view>
          </view>
          <view class="distribution-method" v-if="showPickUpBySelf"
            >({{ $t("order.code") }})</view
          >
        </template>
        <view v-if="isShop" class="select-shop">
          ({{ $t("order.codeTake") }}）
        </view>
      </view>
    </template>
    <view
      class="content"
      @click="$emit('toAddress')"
      v-else-if="csa == 1 && address && address.id"
    >
      <view class="content_text">
        <text>提货人 :</text>
        <text style="margin-left: 20rpx">{{ address.name }} </text>
        <text style="margin-left: 20rpx">{{
          address.mobile | noPassByMobile
        }}</text>
      </view>
      <view class="content_icon content_txt">
        <text>更换</text>
        <u-icon name="arrow-right" size="23rpx"></u-icon>
      </view>
    </view>
    <template v-else>
      <view class="distribution-top">
        <template v-if="!isShop">
          <view class="distribution-address">{{ $t("common.noAddress") }}</view>
          <view class="distribution-addressdetails">
            <view>{{ $t("common.chooseAddress") }}</view>
            <i
              class="iconfont icon-arrow-right"
              style="font-size: 22rpx; color: #cdcdcd"
            ></i>
          </view>
        </template>
        <view v-if="isShop" class="select-shop">
          ({{ $t("order.codeTake") }}）
        </view>
      </view>
    </template>
  </view>
</template>

<script>
export default {
  props: {
    address: {
      type: Object,
      default: function () {
        return null;
      }
    },
    send_type_arr: {
      type: Array,
      default: () => {
        return [];
      }
    },
    isShop: {
      type: Boolean,
      default: false
    },
    csa: {
      type: Number,
      default: 0
    }
  },
  computed: {
    showPickUpBySelf() {
      let arr = this.send_type_arr.filter((d) => {
        return d == true;
      });
      if (arr.length) return true;
      return false;
    }
  },
  filters: {
    noPassByMobile(str) {
      if (null != str && str != undefined) {
        var pat = /(\d{3})\d*(\d{4})/;
        return str.replace(pat, "$1****$2");
      } else {
        return "";
      }
    }
  }
};
</script>

<style lang="scss" scoped>
view {
  color: #262626;
}

.content_text {
  font-family: PingFang SC, PingFang SC;
  font-weight: 600;
  font-size: 30rpx;
  color: #262626;
  font-style: normal;
  text-transform: none;
}

.content_icon {
  display: flex;
  justify-content: center;
  align-items: center;
}

.content_text {
  font-family: PingFang SC, PingFang SC;
  font-weight: 600;
  font-size: 30rpx;
  color: #262626;
  font-style: normal;
  text-transform: none;
}

.content {
  width: 85vw;
  margin: 0 auto;
  height: 128rpx;
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: center;
  font-size: 28rpx;
  color: #262626;
  border-bottom: 1px solid #f8f8f8;
}

.distribution {
  position: relative;
  background-color: #ffffff;
  border-radius: 20rpx;
}

.distribution-top {
  position: relative;
  padding: 40rpx 30rpx 32rpx;

  .icon-arrow-right {
    position: absolute;
    right: 30rpx;
    top: 50%;
    transform: translateY(0, -50%);
  }

  .distribution-address {
    line-height: 36rpx;
    font-size: 26rpx;
  }

  .distribution-addressdetails {
    margin-top: 20rpx;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 34rpx;
    font-weight: bold;

    .addressdetails {
      width: 620rpx;
      color: #262626;
      line-height: 48rpx;
      word-break: break-all;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
      /* 这里是超出几行省略 */
      overflow: hidden;
    }

    image {
      width: 12rpx;
      height: 20rpx;
    }
  }

  .distribution-name {
    margin-top: 8rpx;
    display: flex;
    align-items: center;
    line-height: 36rpx;
    font-size: 26rpx;

    view {
      margin-right: 12rpx;
    }
  }

  .distribution-method {
    margin-top: 18rpx;
    font-size: 24rpx;
    color: #f7271f;
  }
}

.distribution-bottom {
  position: absolute;
  bottom: 0;
  left: 1%;
  width: 98%;
  height: 6rpx;
  display: block;
}

.select-shop {
  margin-top: 8rpx;
  font-size: 24rpx;
  line-height: 34rpx;
  color: #f0250e;
}
</style>
